package com.ehotting.edsta.mqbd.monitor.task.active;

import com.ehotting.eaf.redis.service.RedisService;
import com.ehotting.edsta.mqbd.monitor.task.active.module.*;
import com.ehotting.edsta.mqbd.monitor.task.job.ServerActiveTask;
import com.ehotting.edsta.mqbd.monitor.task.job.TcpChannelCheckTask;
import com.ehotting.mqbd.core.logger.ModuleActiveLogger;
import com.ehotting.mqbd.core.manager.AgentLinkManager;
import com.ehotting.mqbd.core.manager.ModuleManager;
import com.ehotting.mqbd.core.manager.SolverInfoManager;
import com.ehotting.mqbd.core.monitor.ActiveManager;
import com.ehotting.mqbd.core.service.MQService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableScheduling
@Order(4)
public class MonitorTaskConfig {

    @Bean(value = "serverActive")
    public ServerActiveTask serverReleaseLoader(ActiveManager activeManager, RedisService redisService){
        ServerActiveTask serverActiveTask = new ServerActiveTask();
        serverActiveTask.setActiveManager(activeManager);
        serverActiveTask.setRedisService(redisService);
        return serverActiveTask;
    }

    @Bean(value = "tcpChannelCheckTask")
    public TcpChannelCheckTask tcpChannelCheckTask(AgentLinkManager agentLinkManager,
                                                   MQService mqService,
                                                   RedisService redisService){
        TcpChannelCheckTask tcpChannelCheckTask = new TcpChannelCheckTask();
        tcpChannelCheckTask.setAgentLinkManager(agentLinkManager);
        tcpChannelCheckTask.setMqService(mqService);
        tcpChannelCheckTask.setRedisService(redisService);
        return tcpChannelCheckTask;
    }


    @Bean(value = "activeManager" )
    public ActiveManager releaseManager(SolverInfoManager solverInfoManager,
                                        ModuleManager moduleManager,
                                        ModuleActiveLogger moduleActiveLogger){
        ActiveManager activeManager = new ActiveManager();
        activeManager.setSolverInfoManager(solverInfoManager);
        activeManager.setModuleManager(moduleManager);
        activeManager.getModuleActiveList().add(new CAEActive(moduleActiveLogger));
        activeManager.getModuleActiveList().add(new CAEUActive(moduleActiveLogger));
        activeManager.getModuleActiveList().add(new DiagnosisPredictActive(moduleActiveLogger));
        activeManager.getModuleActiveList().add(new SignalAnalysisActive(moduleActiveLogger));

        activeManager.getModuleActiveList().add(new CircuitDesignActive(moduleActiveLogger));
        activeManager.getModuleActiveList().add(new DriverAdaptActive(moduleActiveLogger));
        activeManager.getModuleActiveList().add(new ReliabilityActive(moduleActiveLogger));
        activeManager.getModuleActiveList().add(new SimulationActive(moduleActiveLogger));
        activeManager.getModuleActiveList().add(new TestabilityActive(moduleActiveLogger));
        activeManager.getModuleActiveList().add(new PbcDesignActive(moduleActiveLogger));
        return activeManager;
    }

    @Bean(value = "moduleActiveLogger")
    public ModuleActiveLogger mqActiveLogger(){
        return new ModuleActiveLogger("MODULE_ACTIVE");
    }

}
